
var schoolid = null;
var startType = null;
var mask = null;
var count = 1
var login_user = null

$(function() { // 初始化内容

		mask = mui.createMask(); //遮罩层
		mui.init();
		tap_init();
		mui('#pullrefresh').pullRefresh({

			up: { //上拉加载
				height: 50, //可选.默认50.触发上拉加载拖动距离
				auto: true, //可选,默认false.自动上拉加载一次
				contentrefresh: "正在加载...",
				contentnomore: '没有更多数据了',
				callback: function() { //必选，刷新函数，根据具体业务来编写，比如通过ajax从服务器获取新数据；
					window.setTimeout(function() {
						pullupRefresh()
					}, 500);
				}
			}

		})
		login_user = JSON.parse(localStorage.getItem('loginUser'));
		datetime_init();
	

})




function pullupRefresh() {

	
	loadPublicResource()
}


function tap_init() {

	
	mui(".mui-scroll").on("tap", ".mui-control-item", function(e) {
		var id = this.getAttribute("data_id");
		console.log(id)
	
		console.log("跳转")
		window.sessionStorage.setItem("stu_id",id)
		window.location.href = "upAllotResourceFrom.html"
	});


}


function loadPublicResource() {
	var data = {};
	data['page'] = count;
	data["rows"] = 20;

	data['sort'] = "id"
	data['schoolid'] = login_user.schoolid;
	console.log("待分配资源列表=====" + JSON.stringify(data));
	jQuery.ajax({
		type: "post",
		headers: {
			'Authorization': login_user.token
		},
		url: serverip + "fxxz/ggGrid",
		contentType: 'application/json;charset=UTF-8',
		data: JSON.stringify(data),
		dataType: "json",
		timeout: 10000,
		beforeSend: function() {

			mask.show(); //显示遮罩层	
		},
		success: function(res) {
			count++
			mask.close(); //显示遮罩层 	  
			console.log("记录列表" + JSON.stringify(res));
			var arry = res.stu_List;
			loadApp(arry)

			var num = Number(res.total)
			//数据加载完成后执行的操作,隐藏加载页面,显示数据
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //停止正在加载
			mui('#pullrefresh').pullRefresh().enablePullupToRefresh(true); //启用上拉加载
		},
		error: function(e) {

			mask.close(); //显示遮罩层
			mui.alert('系统错误');
			console.log("错误信息====" + JSON.stringify(e));
		}
	});
}


var app = new Vue({
	el: '#app',
	data: {
		show: true,
		todos: []
	},
	methods: {
		// selected: function(todo) {
		// 	var id = todo.id;
		// 	var discount_id = todo.id;


		// 	console.log("跳转")
		// 	window.sessionStorage.setItem("discount_id", JSON.stringify(todo.id))
		// 	window.location.href = "discount_form.html"
		// }
	}
});



function loadApp(data) {


	for (var i = 0; i < data.length; i++) {
		var d = data[i];
		var o = new Object();
		for (var x in d) {
			o[x] = d[x];

			switch (d.auditstatis) {
				case "未审核":
					o.imgsrc = '../../img/waitingimg.png';
					break;
				case "校长审核通过":
					o.imgsrc = '../../img/successimg.png'
					break;
				case "校长审核不通过":
					o.imgsrc = '../../img/errorimg.png'
					break;
				default:
					break;
			}
		}

		app.todos.push(o);
	}

}
